﻿using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

namespace Pomodoro.Helpers
{
    public static class Sound
    {
        /// <summary>
        /// Plays a sound with XNA assemblies. Do not dispose of SoundEffect, that will make it stop
        /// before Windows Phone can play it. Open the stream once for each play, effects play async.
        /// </summary>
        public static void PlaySound(string soundfile)
        {
            PlaySound(1, soundfile);
        }

        public static void PlaySound(int amount, string soundfile)
        {
            if (App.ViewModel.Mute) return;

            for (int t = 0; t < amount; t++)
            {
                using (Stream stream = TitleContainer.OpenStream(soundfile))
                {
                    SoundEffect effect = SoundEffect.FromStream(stream);
                    FrameworkDispatcher.Update();
                    effect.Play();
                }
            }
        }


    }
}
